const Client = require("ftp");
const args = process.argv.slice(2);
const pwd = args[0];
const path = require("path");
const fs = require("fs");
const basePath = "/home/b8313/stable-diffusion-webui/outputs/img2img-images/";
const pattern = new RegExp("[0-9]*-[0-9]*");

let c = new Client();
c.on("ready", () => {
  c.cwd("novalai", (err) => {
    if (err) throw err;
  });
  try {
    const files = fs.readdirSync(basePath);
    files.forEach((file) => {
      // console.log(file);
      const fileNameInFtp = pattern.exec(file)+ file.slice(file.length - 4);
      const totalPath = path.join(basePath, file) ;
      c.put(totalPath, fileNameInFtp, (err) => {
        if (err) {
          throw err;
        }
        console.log(`file ${fileNameInFtp} uploaded!`);
        // fs.unlinkSync(totalPath);
      });

    });
    c.end();
  } catch (e) {
    console.log(e);
  }


});

c.connect({
  host: "server.masaikk.xyz",
  user: "b8313",
  password: pwd
});




